package com.websocket.example.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.CountDownLatch;


@Slf4j
public class ReceiverRedisMessageListener {
    private CountDownLatch latch;

    @Autowired
    public ReceiverRedisMessageListener(CountDownLatch latch) {
        this.latch = latch;
    }


    /**
     * 队列消息接收方法
     *
     * @param jsonMsg
     */
    public void receiveMessage1(String jsonMsg) {
        try {
            log.info("redis 队列1中的数据为 : {}", jsonMsg);
        } catch (Exception e) {
            log.error("[消费redis消息队列1数据失败，失败信息:{}]", e.getMessage());
        }
        latch.countDown();
    }


    public void receiveMessage2(String jsonMsg) {
        try {
            log.info("redis队列2中的数据为 : {}", jsonMsg);
        } catch (Exception e) {
            log.error("[消费redis消息队列2数据失败，失败信息:{}]", e.getMessage());
        }
        latch.countDown();
    }

    /**
     * 队列消息接收方法
     *
     * @param jsonMsg
     */
    public void receiveMessage3(String jsonMsg) {
        try {
            log.info("redis队列3中的数据为 : {}", jsonMsg);
        } catch (Exception e) {
            log.error("[消费redis消息队列3数据失败，失败信息:{}]", e.getMessage());
        }
        latch.countDown();
    }

}